package com.hmall.search.controller;

import com.hmall.common.dto.PageDTO;
import com.hmall.common.pojo.ItemDoc;
import com.hmall.common.pojo.RequestItems;
import com.hmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    SearchService searchService;

    @GetMapping("/suggestion")
    public List<String> getSuggestionList(@RequestParam("key") String key) {
        return searchService.getSuggestionList(key);
    }

    @PostMapping("/filters")
    public Map<String, List<String>> filters(@RequestBody RequestItems requestItems){
       return searchService.filters(requestItems);
    }

    @PostMapping("/list")
    public PageDTO<ItemDoc> getItems(@RequestBody RequestItems requestItems){
        return searchService.getItems(requestItems);
    }
}
